package pit.com.ordermobilesystem.fragment;

import pit.com.ordermobilesystem.BaseFragment;
import pit.com.ordermobilesystem.R;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class BaseTabFragment extends Fragment {
		public String titleTab="";
		public String getTitleTab() {
			return titleTab;
		}
	
		public void setTitleTab(String titleTab) {
			this.titleTab = titleTab;
		}
	    @Override
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);

	    }

	    @Override
	    public View onCreateView(LayoutInflater inflater, ViewGroup container,
	            Bundle savedInstanceState) {
	        View rootView = inflater.inflate(R.layout.container_fragment, container, false);
	        return rootView;
	    }
	    
	    public void addFragment(BaseFragment mFrag){
			FragmentTransaction t = getChildFragmentManager().beginTransaction();
			t.add(R.id.container_framelayout,mFrag,mFrag.getName());
			t.addToBackStack(mFrag.getName());
			t.commit();	
			getChildFragmentManager().executePendingTransactions();
	    }
	
	    public void replaceFragment(Fragment fragment, boolean addToBackStack) {
		    FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
		    if (addToBackStack) {
		        transaction.addToBackStack(null);
		    }
		    transaction.replace(R.id.container_framelayout, fragment);
		    transaction.commit();
		    getChildFragmentManager().executePendingTransactions();
		}
		 
		public boolean popFragment() {
		    
		    boolean isPop = false;
		    if (getChildFragmentManager().getBackStackEntryCount() > 0) {
		        isPop = true;
		        getChildFragmentManager().popBackStack();
		    }
		    return isPop;
		}	    
	    
}
